package com.heimo.agentlicence.task;

import java.util.List;

import org.apache.http.NameValuePair;

import android.content.Context;
import android.util.Log;

import com.heimo.agentlicence.htmlchecker.DisciplineChecker;

public class DisciplineLoadTask  extends BasicTask {
	private final String TAG = "DisciplineLoadTask";
	
	public DisciplineLoadTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
		this.loadMsg = "Loading data from remote site...";
	}

	public void fnLoadPage() {
		try {
			super.onPreExecute();
			Log.d(TAG, "DisciplineLoadTask.fnLoadPage()");
			super.execute(LOAD_DISCIPLINE_LOAD_PAGE);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		Log.d(TAG, "DisciplineLoadTask.onPostExecute()");
		DisciplineChecker lc = new DisciplineChecker();
		List<NameValuePair> nvp = null;
		try {
			nvp = lc.fnGetAgentModelFromHtml(result);
			if (this.listener != null) {
				this.listener.onTaskCompleted(nvp);
			}
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
		
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}

}